package emulator.hardware.clock;

import emulator.util.Handle;

public class ClockHandleImplementation extends Handle implements ClockHandle {

	private int max_ticks = 1;
	private int ticks_elapsed = 0;
	private ClockImplementation clock;
	
	ClockHandleImplementation(ClockImplementation clock)
	{
		this.clock = clock;
	}
	
	ClockHandleImplementation(ClockImplementation clock, int max_ticks)
	{
		this.clock = clock;
		this.max_ticks = max_ticks;
	}
	
	@Override
	public void tick() {
		tick(1);
	}

	@Override
	public void tick(int x) {
		ticks_elapsed += x;
		if (ticks_elapsed >= max_ticks)
		{
			clock.countTicks(this, ticks_elapsed);
			ticks_elapsed = 0;
		}	
	}

}
